package com.qf.j2205.service.impl;

import com.qf.j2205.dao.VipUserMapper;
import com.qf.j2205.entity.VipUser;
import com.qf.j2205.service.VipUserService;
import com.qf.j2205.util.MybitesUtil;

import java.util.List;

/**
 * @ClassName VipUserServiceImpl
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/17 10:31
 * @Version 1.0
 **/
public class VipUserServiceImpl implements VipUserService {
    /**
     * 添加vip信息
     * @param vip
     * @return
     */
    @Override
    public boolean insertVipUser(VipUser vip){
        VipUserMapper mapper = MybitesUtil.getSession().getMapper(VipUserMapper.class);
        int i = mapper.insertVipUser(vip);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }

    /**
     * 查询全部数据
     * @return
     */
    @Override
    public List<VipUser> findAll(){
        VipUserMapper mapper = MybitesUtil.getSession().getMapper(VipUserMapper.class);
        List<VipUser> users=null;
        List<VipUser> all = mapper.findAll();
        users = all;
        return users;
    }

    /**
     * 根据id进行逻辑删除
     * @param vid
     * @return
     */
    @Override
    public boolean deleteVip(int vid){
        VipUserMapper mapper = MybitesUtil.getSession().getMapper(VipUserMapper.class);
        int i = mapper.deleteVip(vid);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }

    /**
     * 条件查询
     * @param name
     * @param vcid
     * @param type
     * @return
     */
   @Override
    public List<VipUser> conditionFind(String name, String vcid, String type){
        VipUserMapper mapper = MybitesUtil.getSession().getMapper(VipUserMapper.class);
        List<VipUser> users=null;
        List<VipUser> all = mapper.conditionFind(name,vcid,type);
        users = all;
        return users;
    }

    /**
     * 根据id查询
     * @param vid
     * @return
     */
   @Override
    public  VipUser findOneById(int vid){
        VipUserMapper mapper = MybitesUtil.getSession().getMapper(VipUserMapper.class);
        VipUser oneById = mapper.findOneById(vid);
        return oneById;
    }

    /**
     * 更新会员信息
     * @param vip
     * @return
     */
   @Override
    public boolean editVip(VipUser vip){
        VipUserMapper mapper = MybitesUtil.getSession().getMapper(VipUserMapper.class);
        int i = mapper.editVip(vip);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }
}
